package com.soxing.webrain.brush.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.soxing.webrain.brush.common.util.PageUtils;
import com.soxing.webrain.brush.dao.entity.Task;
import com.soxing.webrain.brush.dao.service.impl.StatResultServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.soxing.webrain.brush.dao.entity.StatResult;
import com.soxing.webrain.brush.domain.view.R;

import javax.annotation.Resource;

/**
 * 被试信息
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2024-04-02 10:02:28
 */
@RestController
@RequestMapping("/statResult")
public class StatResultController {
    @Resource
    private StatResultServiceImpl statResultService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = statResultService.queryPage(params);

        return R.ok().data("page", page);
    }

    @RequestMapping("/getListByTesteeId")
    public R getListByTesteeId(@RequestParam Integer id){
        List<StatResult> statResultList = statResultService.list(new LambdaQueryWrapper<StatResult>().eq(StatResult::getTesteeId,id).orderByDesc(StatResult::getId));

        return R.ok().data("list", statResultList);
    }

    @RequestMapping("/getInfoByTaskId")
    public R getInfoByTaskId(@RequestParam Integer id){
        StatResult statResult = statResultService.getOne(new LambdaQueryWrapper<StatResult>().eq(StatResult::getTaskId,id));

        return R.ok().data("statResult", statResult);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        StatResult statResult = statResultService.getById(id);

        return R.ok().data("paradigm", statResult);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StatResult statResult){
        statResultService.saveOrUpdate(statResult);

        return R.ok().data("data", statResult);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StatResult statResult){
        statResultService.updateById(statResult);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam Integer id){
        statResultService.removeById(id);

        return R.ok();
    }

}
